home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 261 / SOMC Family Forum 261.iso / Xtras / Behavior Library.cst / 00030_Script_Net Preload Net Thing < prev    next >
Text File  |  1997-11-17  |  5KB  |  147 lines

  1. -- Net preloadNet Thing
  2.  
  3.  
  4. -- behavior library version 1.1
  5. -- preloadNetThingBuddy Behavior script
  6. -- 2/13/97 Chris Walcott
  7.  
  8. -- This behavior can be used to as a general purpose preloadNetThing script.
  9. -- The behavior is assigned to a frame Script.  
  10. -- The required custom properties are:
  11.  
  12. -- "Channel number of field" - this is the field that will contain the list
  13. -- of URL's that are to be preloaded. Use the Score channel number of the field.
  14. -- "Debug" - If TRUE, status lines will print to the message window.
  15. -- "AutoLoad URL" - If set to "AutoLoad", a preloadNetThing will be performed on
  16. -- the URL provided in the next property field.  If set to "Manual", you will need 
  17. -- to perform the gotoNetPage operation yourself.
  18. -- "Target URL" -  if AutoLoad is set, a gotoNetPage operation will be performed 
  19. -- on this URL.
  20.  
  21.  
  22. property pListURLs         -- field containing URL's to preload
  23. property pDebug            -- field containing URL's to preload
  24. property pAutoLoad         -- field containing URL's to preload
  25. property pURL              -- which URL is called if AutoLoad is set
  26. property pInitializeDone   -- field containing URL's to preload
  27.  
  28. property pWaitingList          -- list of URL's waiting to be retrieved
  29. property pDispatchedListURL    -- list of preloaded URL's
  30. property pDispatchedListNetID  -- list of preloaded URL net ID's
  31.  
  32.  
  33.  
  34. on getPropertyDescriptionList
  35.   set description = [:]
  36.   
  37.   addprop description, #pListURLs, [#default: member 1, #format: #field,   #comment: "Member name of URL list:"]
  38.   
  39.   addprop description, #pDebug, [#default: 0, #format:#boolean, #comment: "Debug:"]
  40.   
  41.   addprop description, #pAutoLoad, [#default: #AutoLoad, #format:#symbol, #comment: "AutoLoad URL:", #range: [#AutoLoad, #Manual]]
  42.   
  43.   addprop description, #pURL, [#default: "http://", #format: #string,   #comment: "Target URL for AutoLoad:"]
  44.   
  45.   return description
  46. end
  47.  
  48. on beginSprite me
  49.   
  50.   set pInitializeDone = FALSE
  51. end
  52.  
  53.  
  54. on exitFrame me
  55.   
  56.   if  NOT pInitializeDone = TRUE then
  57.     initializeNetList
  58.     cursor 4
  59.     set pInitializeDone = TRUE
  60.   end if
  61.   
  62.   if NetDoneList() > 0 then
  63.     go to the frame
  64.   else
  65.     if pAutoLoad = TRUE then
  66.       cursor 0
  67.       gotoNetPage pURL
  68.     else   
  69.       go to frame "done"
  70.       cursor 0
  71.     end if
  72.   end if
  73.   
  74. end
  75.  
  76.  
  77. on initializeNetList me
  78.   
  79.   -- initialize the lists
  80.   set pWaitingList = []
  81.   set pDispatchedListURL = []
  82.   set pDispatchedListNetID = []
  83.   repeat with i = 1 to the lineCount of member pListURLs
  84.     set theLine = line i of field pListURLs
  85.     append( pWaitingList, theLine)
  86.   end repeat
  87.   
  88.   if pDebug = TRUE then
  89.     put "List of assets to preload" & RETURN & pWaitingList & RETURN
  90.   end if
  91.   
  92.   
  93. end
  94.  
  95.  
  96. on netDoneList me
  97.   
  98.   -- check the dispatch list for assest that have arrived
  99.   repeat with iListAsset = 1 to count( pDispatchedListURL )
  100.     -- if the asset has arrived
  101.     if NetDone( getAt( pDispatchedListNetID, iListAsset ) ) then
  102.       if pDebug = TRUE then
  103.         put "Asset Received:" & getAt( pDispatchedListURL, iListAsset )
  104.       end if
  105.       -- remove if from the dispatch list
  106.       deleteAt pDispatchedListURL, iListAsset
  107.       deleteAt pDispatchedListNetID, iListAsset
  108.     end if
  109.   end repeat
  110.   
  111.   -- check the dispatch and waiting list: how many things
  112.   -- can we preload?  Current stream limit is set to 4
  113.   set iCountDispatch to min( count( pWaitingList ), 4 - count( pDispatchedListURL ) )
  114.   repeat with iFreeSpot = 1 to iCountdispatch
  115.     
  116.     -- start the  preloadNetThing operation on the next waiting asset
  117.     set getMe = getAt( pWaitingList, 1 )
  118.     if pDebug = TRUE then
  119.       put "Asset Preloading" getMe
  120.     end if
  121.     preloadNetThing getMe
  122.     
  123.     -- move the asset to the dispatched list
  124.     append pDispatchedListURL, getAt( pWaitingList, 1 )
  125.     append pDispatchedListNetID, getLatestNetID()
  126.     -- remove the asset from the waiting list
  127.     deleteAt pWaitingList, 1
  128.   end repeat
  129.   
  130.   -- check the dispatch list for assest that have arrived
  131.   set netDoneListCount = count( pDispatchedListURL ) + count( pWaitingList )
  132.   if pDebug = TRUE then
  133.     put "Assets remaining to process:" netDoneLIstCount
  134.   end if
  135.   return netDoneListCount
  136.   
  137. end
  138.  
  139. on getBehaviorDescription
  140.   return "Preloads a file from the internet to the disk cache so it can be used later without a download delay. Loads the file while the current movie continues playing. After an item is preloaded, it can be displayed immediately because it is taken from the local browserÆs cache rather than from the network. "& RETURN & "PARAMETERS:" & RETURN & "ò Channel Number of Field - this is the field that will contain the list"
  141.   -- of URL's that are to be preloaded. Use the Score channel number of the field.
  142.   -- "Debug" - If TRUE, status lines will print to the message window.
  143.   -- "AutoLoad URL" - If set to "AutoLoad", a preloadNetThing will be performed on
  144.   -- the URL provided in the next property field.  If set to "Manual", you will need 
  145.   -- to perform the gotoNetPage operation yourself.
  146.   -- "Target URL" -  if AutoLoad is set, a gotoNetPage operation will be performed 
  147.   -- on this URL.